<?php




/**
* Produces a color block
*/

$color_id = $variable->get('id', 'integer', 0);
$code = $variable->get('code', 'string', ''); 

$colors = new colors();

function color_separation($rrggbb='000000')
{
	$colors=array();
	$rgb = preg_match_all('/([0-9A-F]{2})/is', $rrggbb, $colors);
	$rgb = array_map('hexdec', $colors[1]);
	return $rgb;
}

if($color = $colors->details($color_id, $code))
{
	$block_color_rgb = color_separation($color['color_foreground']);
	$border_color_rgb = color_separation($color['color_background']);
	$height = $width = 18;
	$block = imagecreate($width, $height) or die("GD failed to initialize");
	$background_color = imagecolorallocate($block, $block_color_rgb[0], $block_color_rgb[1], $block_color_rgb[2]);
	$border_color = imagecolorallocate($block, $border_color_rgb[0], $border_color_rgb[1], $border_color_rgb[2]);
	imagerectangle($block, 0, 0, $width-1, $height-1, $border_color);
	headers::cache(); headers::image('png'); imagepng($block, null); imagedestroy($block);
}
?>